import 'package:flutter/material.dart';
import 'notify_item.dart';

class HomeList extends StatefulWidget {
  const HomeList({super.key, required this.list});
  final List list;
  @override
  State<HomeList> createState() => _HomeListState();
}

class _HomeListState extends State<HomeList> {
  // 头部组件
  Widget getTitleWidget() {
    return Padding(
        padding: const EdgeInsets.all(10),
        child: Row(
          children: [
            Image.asset(
              "assets/images/notice@2x.png",
              width: 25,
              height: 25,
            ),
            const SizedBox(
              width: 5,
            ),
            const Text(
              "社区",
              style: TextStyle(
                  color: Colors.black,
                  fontSize: 16,
                  fontWeight: FontWeight.bold),
            ),
            const Text(
              "公告",
              style: TextStyle(
                  color: Colors.orange,
                  fontSize: 16,
                  fontWeight: FontWeight.bold),
            ),
          ],
        ));
  }

// 获取列表渲染内容
  Widget getListBuilder() {
    return ListView(
      // shrinkWrap 限制滚动的距离长度(根据子组件的高度决定)
      shrinkWrap: true,
      physics: const NeverScrollableScrollPhysics(), // 双层嵌套的滚动,禁止内层滚动
      children: widget.list.map((item) {
        return NotifyItem(item: item);
      }).toList(),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [getTitleWidget(), getListBuilder()],
    );
  }
}
